﻿using DataAccessLayer;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BusinessLogicLayer
{
    public class CungCapBLL
    {
        NhaCungCapDataContext DB = new NhaCungCapDataContext();
        public List<NHACUNGCAP> LayTatCa()
        {
            return DB.NHACUNGCAPs.ToList();
        }
        public List<NHACUNGCAP> search(string mancc)
        {
            return DB.NHACUNGCAPs.Where(ncc => ncc.Mancc == mancc).ToList();
        }
        //public Object search(string mancc)
        //{
        //    var q = (from ncc in DB.NHACUNGCAPs where ncc.Mancc == mancc select ncc).ToList();
        //    return q;
        //}
        public string insert(string mancc, string tenncc, string diachi, string dienthoai, string email, string tp)
        {
            NHACUNGCAP th = new NHACUNGCAP();
            th.Mancc = mancc;
            th.Tenncc = tenncc;
            th.Diachincc = diachi;
            th.Dienthoai = dienthoai;
            th.Email= email;
            th.Thanhpho = tp;
            try
            {
                DB.NHACUNGCAPs.InsertOnSubmit(th);
                DB.SubmitChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return "Có lỗi khi thêm vào CSDL\r\n" + e;
            }
            return "Thêm thành công";
           
        }
        public void delete(string mancc)
        {
            NHACUNGCAP th = DB.NHACUNGCAPs.Where(p => p.Mancc == mancc).FirstOrDefault();
            DB.NHACUNGCAPs.DeleteOnSubmit(th);
            DB.SubmitChanges();
        }
    }
}
